package com.Apo1o.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Auther: Apo1o.
 * @Date: 2023/10/31-10-31-20:26
 * @Description： com.Apo1o.config
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

        //Swagger界面中显示的基本信息
        private ApiInfo apiInfo(){
//配置基本信息
            Contact Apo1o = new Contact("Apo1o",
                    "http://www.Apo1o.com/index.php/", "Apo1o@163.com");
            return new ApiInfoBuilder()
//标题
                    .title("栏舍管理")
                    .description("欢迎访问栏舍管理接口文档")
//基本信息
                    .contact(Apo1o)
//版本号
                    .version("1.0.0")
//创建
                    .build();
        }
        //配置Controller的包路径
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
//传入要扫描的包结构
                    .apis(RequestHandlerSelectors.basePackage("com.Apo1o.controller")
                    )
                    .paths(PathSelectors.any())
                    .build();
        }
    }

